home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / CHAP12.ZIP / PATRON / DRAGDROP.CPP < prev    next >
C/C++ Source or Header  |  1993-06-27  |  4KB  |  181 lines

  1. /*
  2.  * DRAGDROP.CPP
  3.  * Drag-Drop for Chapter 12:  No modifications
  4.  *
  5.  * Member functions of the CPages class concerned with drag-drop and
  6.  * other object-placement functionality.  Moved here to clean up
  7.  * CPAGES.CPP somewhat.
  8.  *
  9.  *
  10.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  11.  *
  12.  * Kraig Brockschmidt, Software Design Engineer
  13.  * Microsoft Systems Developer Relations
  14.  *
  15.  * Internet  :  kraigb@microsoft.com
  16.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  17.  */
  18.  
  19.  
  20.  
  21. #include "patron.h"
  22.  
  23.  
  24. /*
  25.  * CPages::UTestDroppablePoint
  26.  *
  27.  * Purpose:
  28.  *  Returns if the point in pptl is on the paper in the current page
  29.  *  and alternately if it's within horizontal or vertical inset
  30.  *  regions.
  31.  *
  32.  * Parameters:
  33.  *  pptl            LPPOINTL containing the point in screen coordinates.
  34.  *
  35.  * Return Value:
  36.  *  UINT            A UDROP_* value.
  37.  */
  38.  
  39. UINT CPages::UTestDroppablePoint(LPPOINTL pptl)
  40.     {
  41.     POINT       pt;
  42.     RECT        rc, rcT, rcC;
  43.     UINT        uRet;
  44.  
  45.     POINTFROMPOINTL(pt, *pptl);
  46.     ScreenToClient(m_hWnd, &pt);
  47.  
  48.     CalcBoundingRect(&rc, FALSE);
  49.  
  50.     GetClientRect(m_hWnd, &rcC);
  51.     IntersectRect(&rcT, &rc, &rcC);
  52.  
  53.     //Check for at least a client area hit.
  54.     if (!PtInRect(&rcT, pt))
  55.         return UDROP_NONE;
  56.  
  57.     uRet=UDROP_CLIENT;
  58.  
  59.     //Scroll checks happen on client area, not document area
  60.     if (PtInRect(&rcC, pt))
  61.         {
  62.         //Check horizontal inset
  63.         if (pt.x <= rcC.left+(int)m_uScrollInset)
  64.             uRet |= UDROP_INSETLEFT;
  65.         else if (pt.x >= rcC.right-(int)m_uScrollInset)
  66.             uRet |= UDROP_INSETRIGHT;
  67.  
  68.         //Check vertical inset
  69.         if (pt.y <= rcC.top+(int)m_uScrollInset)
  70.             uRet |= UDROP_INSETTOP;
  71.         else if (pt.y >= rcC.bottom-(int)m_uScrollInset)
  72.             uRet |= UDROP_INSETBOTTOM;
  73.         }
  74.  
  75.     return uRet;
  76.     }
  77.  
  78.  
  79.  
  80.  
  81. /*
  82.  * CPages::DrawDropTargetRect
  83.  *
  84.  * Purpose:
  85.  *  Draws a dotted rectangle on the Pages window to show where
  86.  *  a drop might occur.  This is a toggle function.
  87.  *
  88.  * Parameters:
  89.  *  pptl            LPPOINTL containing the upper-left point
  90.  *                  in screen coordinates.
  91.  *  pszl            LPSIZEL containing the rect extents in device units.
  92.  *
  93.  * Return Value:
  94.  *  None
  95.  */
  96.  
  97. void CPages::DrawDropTargetRect(LPPOINTL pptl, LPSIZEL pszl)
  98.     {
  99.     static POINTL   ptl;
  100.     static SIZEL    szl;
  101.     POINT           pt;
  102.     RECT            rc, rcT;
  103.     HDC             hDC;
  104.  
  105.     if (NULL==pptl && NULL==pszl)
  106.         {
  107.         /*
  108.          * This case is used from WM_PAINT in pagewin.cpp so we can
  109.          * control the proper visibility of the drag rectangle when
  110.          * we're scrolling.  If drag-drop happens between two apps,
  111.          * then any ScrollWindow will cause a WM_PAINT after we
  112.          * leave DragOver, so that paint would normally overwrite the
  113.          * last drawn rectangle.  To alleviate that, WM_PAINT will
  114.          * remove the last rect by sending us NULLs, paint, then
  115.          * reinstate the rectangle.
  116.          */
  117.         pptl=&ptl;
  118.         pszl=&szl;
  119.         }
  120.     else
  121.         {
  122.         ptl=*pptl;
  123.         szl=*pszl;
  124.  
  125.         //This flag is only affected from IDropTarget, not WM_PAINT calls.
  126.         m_fDragRectShown=!m_fDragRectShown;
  127.         }
  128.  
  129.     POINTFROMPOINTL(pt, *pptl);
  130.     ScreenToClient(m_hWnd, &pt);
  131.     SetRect(&rc, pt.x, pt.y, pt.x+(int)pszl->cx, pt.y+(int)pszl->cy);
  132.  
  133.     CalcBoundingRect(&rcT, FALSE);
  134.     IntersectRect(&rc, &rc, &rcT);
  135.  
  136.     if (!IsRectEmpty(&rc))
  137.         {
  138.         hDC=GetDC(m_hWnd);
  139.         DrawFocusRect(hDC, &rc);
  140.         ReleaseDC(m_hWnd, hDC);
  141.         }
  142.  
  143.     return;
  144.     }
  145.  
  146.  
  147.  
  148.  
  149. /*
  150.  * CPages::AdjustPosition
  151.  *
  152.  * Purpose:
  153.  *  Adjusts a point for the scrolling offset and then converts it and
  154.  *  a size from device into LOMETRIC units.
  155.  *
  156.  * Parameters:
  157.  *  pptl            LPPOINTL to adject and convert
  158.  *  pszl            LPSIZEL to convert
  159.  *
  160.  * Return Value:
  161.  *  None
  162.  */
  163.  
  164. void CPages::AdjustPosition(LPPOINTL pptl, LPSIZEL pszl)
  165.     {
  166.     RECT        rc;
  167.  
  168.     SetRect(&rc, m_xPos+(int)pptl->x
  169.         , m_yPos+(int)pptl->y, (int)pszl->cx, (int)pszl->cy);
  170.  
  171.     RectConvertMappings(&rc, NULL, FALSE);
  172.  
  173.     pptl->x=rc.left;
  174.     pptl->y=rc.top;
  175.  
  176.     pszl->cx=rc.right;
  177.     pszl->cy=rc.bottom;
  178.  
  179.     return;
  180.     }
  181.